package com.jiangchuang.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 统一返回结果封装
 */
@Data
public class Result<T> {
    @ApiModelProperty(value = "响应码")
    private Integer code;

    @ApiModelProperty(value = "响应错误描述")
    private String msg;

    @ApiModelProperty(value = "响应数据")
    private T data;
    public Result() {
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Result<T> ok() {
        return new Result<>(200, "success");
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(200, "success", data);
    }

    public static <T> Result<T> warn(String msg) {
        return new Result<>(201, msg);
    }

    public static <T> Result<T> fail() {
        return new Result<>(500, "failed");
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<>(500, msg);
    }

    public static <T> Result<T> error(T t, String msg, int code) {
        return new Result<>(code, msg, t);
    }

    public static <T> Result<T> exception() {
        return new Result<>(700, "server error, pls contact manager!");
    }

    public static <T> Result<T> exception(String msg) {
        return new Result<>(700, msg);
    }

    public static Result noLogin() {
        return new Result(501, "身份信息失效，请重新登录.");
    }

}